//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Dialogue node
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to.
//   Cell 4 - If 1, this creature goes straight to the nav point immediately
//     and never returns

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_abil;
short mess1 = 0;
short mess2 = 0;
short mess3 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Bennhold");
	change_max_health(ME,200);
	set_boss_level(ME,2);
	
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(101,11,1);
	begin_talk_mode(27);
	
break;

beginstate START_STATE; 
	// if out of sight of party heal ststuses
	if (can_see_char(1000) == FALSE) {
		force_char_status(ME,6,0);
		force_char_status(ME,20,0);
		force_char_status(ME,2,0);
		}
		
	if (path_a_or_b == 2) {
		if ((get_health(ME) < get_max_health(ME) - 200) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			last_abil = get_current_tick();
			heal_char(ME,400);
			if (get_nearest_party_char(7) >= 0) 
				print_named_str(ME,"inhales the contents of a healing pod.");
			
			}
		if (dist_to_nav_point(ME,1) <= 2)
			path_a_or_b = 3;
			else approach_nav_point(ME,1,1);
		end();
		}
	if (path_a_or_b == 4) {
		if ((get_health(ME) < get_max_health(ME) - 200) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			last_abil = get_current_tick();
			heal_char(ME,400);
			if (get_nearest_party_char(7) >= 0) 
				print_named_str(ME,"inhales the contents of a healing pod.");
			
			}
		if (dist_to_nav_point(ME,2) <= 2)
			path_a_or_b = 5;
			else approach_nav_point(ME,2,1);
		end();
		}
	if (path_a_or_b == 6) {
		if ((get_health(ME) < get_max_health(ME) - 200) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			last_abil = get_current_tick();
			heal_char(ME,400);
			if (get_nearest_party_char(7) >= 0) 
				print_named_str(ME,"inhales the contents of a healing pod.");
			
			}
		if (dist_to_nav_point(ME,0) <= 1) {
			path_a_or_b = 7;
			set_walk_speed(ME,0);
			}
			else approach_nav_point(ME,0,1);
		end();
		}
	

	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		if (path_a_or_b == 0) 
			path_a_or_b = 1;
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (path_a_or_b == 0) {
		if (get_nearest_party_char(7) >= 0) {
			path_a_or_b = 1;
			set_attitude(ME,10);
			if (gf(69,7) == 0) {
				sf(69,7,1);
				talk_no_exit(10);
				}
			}
		
		}
	if (path_a_or_b == 1) {
		if (get_health(ME) < get_max_health(ME) - 200) {
			path_a_or_b = 2;
			set_foe_target(ME,-1);
			begin_talk_mode(24);
			}
		}
	if (path_a_or_b == 3) {
		if (get_health(ME) < get_max_health(ME) - 400) {
			path_a_or_b = 4;
			set_foe_target(ME,-1);
			print_named_str(ME,"runs away.");
			}
		}
	if (path_a_or_b == 5) {
		if ((mess1 == 0) && (get_nearest_party_char(6) >= 0)) {
			mess1 = 1;
			print_str_color("You see some bandits approaching from the south.",2);
			activate_hidden_group(5);
			}
		if (get_health(ME) < get_max_health(ME) - 400) {
			path_a_or_b = 6;
			set_foe_target(ME,-1);
			print_named_str(ME,"runs away.");
			}
		}

	if ((get_attitude(ME) >= 10) && (path_a_or_b == 8)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if (gf(69,7) == 0) {
		sf(69,7,1);
		set_attitude(ME,10);
		talk_no_exit(10);
		}


	if (path_a_or_b == 1) {
		if (get_health(ME) < get_max_health(ME) - 200) {
			path_a_or_b = 2;
			set_foe_target(ME,-1);
			begin_talk_mode(24);
			}
		}
	if (path_a_or_b == 3) {
		if (get_health(ME) < get_max_health(ME) - 400) {
			path_a_or_b = 4;
			set_foe_target(ME,-1);
			print_named_str(ME,"runs away.");
			}
		}
	if (path_a_or_b == 5) {
		if ((mess1 == 0) && (get_nearest_party_char(6) >= 0)) {
			mess1 = 1;
			print_str_color("You see some bandits approaching from the south.",2);
			activate_hidden_group(5);
			}
		if (get_health(ME) < get_max_health(ME) - 400) {
			path_a_or_b = 6;
			set_foe_target(ME,-1);
			print_named_str(ME,"runs away.");
			}
		}


	if ((mess2 == 0) && (get_health(ME) < (get_max_health(ME) * 2) / 3)) {
		mess2 = 1;
		print_str_color("You see some bandits approaching from the south.",2);
		set_attitude(56,10);
		set_act_at_dist(56,1);
		set_attitude(57,10);
		set_act_at_dist(57,1);
		set_attitude(58,10);
		set_act_at_dist(58,1);
		begin_talk_mode(26);
		}
	if ((mess3 == 0) && (get_health(ME) < (get_max_health(ME) * 1) / 3)) {
		mess3 = 1;
		print_str_color("Bennhold calls for more creations to come help him.",2);
		set_attitude(59,10);
		set_act_at_dist(59,1);
		set_attitude(60,10);
		set_act_at_dist(60,1);
		set_attitude(61,10);
		set_act_at_dist(61,1);
		}

	if ((path_a_or_b == 7) && (tick_difference(last_abil,get_current_tick()) > 1) && (is_combat()) && (get_nearest_party_char(6) >= 0)) {
		last_abil = get_current_tick();
		inc_flag(69,6,1);
		}
	if (gf(69,6) == 12) {
		path_a_or_b = 8;
		set_attack_bonus(ME,8);
		set_walk_speed(ME,28);
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(0) == 0) {
		print_str("Talking: You make a bit of small talk with this person, but don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(0));
	break;